﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：WarehouseInfo
// 文件功能描述：仓库管理
//
// 
// 创建标识：2012-02-08 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class WarehouseInfo
    {
        /// <summary>
        /// 主键，仓库ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 仓库名称
        /// </summary>
        public string Warehouse_Name
        {
            get;
            set;
        }
        /// <summary>
        /// 仓库负责人
        /// </summary>
        public string Manager
        {
            get;
            set;
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get;
            set;
        }

        private DataAccessWarehouse dar;
        private int Warehousecount;
        public int _Warehousecount
        {
            get { return Warehousecount; }
        }
        public WarehouseInfo(bool isgetcount)
        {
            dar = new DataAccessWarehouse();
            if (isgetcount)
            {
                Warehousecount = GetWarehouseCount();
            }
        }
        public WarehouseInfo()
        { }

        /// <summary>
        /// 获取仓库数量
        /// </summary>
        /// <returns></returns>
        private int GetWarehouseCount()
        {
            return dar.GetWarehouseCount();
        }

        /// <summary>
        /// 获取仓库信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<WarehouseInfo> SelWarehouseInfo(int pagesize, int startindex, string strquery)
        {
            IList<WarehouseInfo> warelist = new List<WarehouseInfo>();
            WarehouseInfo wareinfo;
            DataSet ds = dar.SelWarehouseInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                wareinfo = new WarehouseInfo()
                {
                    ID = Convert.ToInt32(item["ID"]),
                    Warehouse_Name = item["Warehouse_Name"].ToString(),
                    Manager = item["Manager"].ToString(),
                    Remark = item["Remark"].ToString()
                };
                warelist.Add(wareinfo);
            }
            return warelist;
        }

        /// <summary>
        /// 保存仓库(新增界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveWarehouse(WarehouseInfo ware)
        {
            object[] warepara = new object[] { ware.Warehouse_Name, ware.Manager, ware.Remark };
            return dar.SaveWarehouse(warepara);
        }

        /// <summary>
        /// 保存仓库(修改界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveWarehouseEdit(WarehouseInfo ware)
        {
            object[] warepara = new object[] { ware.ID, ware.Warehouse_Name, ware.Manager, ware.Remark };
            return dar.SaveWarehouseEdit(warepara);
        }

        /// <summary>
        /// 删除仓库
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteWarehouse(string id)
        {
            return dar.DeleteWarehouse(id);
        }

        /// <summary>
        /// 根据编号获取一条仓库信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public WarehouseInfo GetWarehouseInfoOne(string id)
        {
            dar = new DataAccessWarehouse();
            DataSet ds = dar.GetWarehouseInfoOne(id);
            WarehouseInfo info = new WarehouseInfo();
            info.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
            info.Warehouse_Name = ds.Tables[0].Rows[0]["Warehouse_Name"].ToString();
            info.Manager = ds.Tables[0].Rows[0]["Manager"].ToString();
            info.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
            return info;
        }

        public static string GetWarehouseName(int id)
        {
            return DataAccessWarehouse.GetWarehouseName(id);
        }
    }
}
